//
//  ResponseCodeCheck.m
//  Ridding
//
//  Created by zys on 12-4-11.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ResponseCodeCheck.h"
static ResponseCodeCheck *responseCodeCheck=nil;
@implementation ResponseCodeCheck
@synthesize staticInfo;


- (id)init
{
    self = [super init];
    if (self) {
        staticInfo=[StaticInfo getSinglton];
    }
    return self;
}

+ (ResponseCodeCheck*)getSinglton
{
    @synchronized(self) {
        if (responseCodeCheck == nil) {
            responseCodeCheck=[[self alloc] init]; 
        }
    }
    return responseCodeCheck;
}

-(BOOL)checkResponseCode:(int)code statusCode:(int)statusCode{
    if(code==1&&statusCode==200){
        return true;
    }
    else if(statusCode == -300) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"退出活动失败" 
                                                        message:@"请确实所有队员退出之后，队长才能退出" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];

    }
    else if(statusCode == -310) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"退出活动失败" 
                                                        message:@"活动不存在" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
        
    }
    else if(statusCode == -302) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"退出活动失败" 
                                                        message:@"用户不在该骑行活动中" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
        
    }
    else if(statusCode == -202) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"用户没有权限" 
                                                        message:@"只有队长才有该权限" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
        
    }
    else if(statusCode == -100) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"json解释失败" 
                                                        message:@"数据解析失败，请重新发送请求" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
        
    }
    else if(statusCode!=200){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"连接服务器失败" 
                                                        message:@"连接服务器失败，请检查当前网络" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
    }else if(code!=1){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"连接服务器失败" 
                                                        message:@"连接服务器失败，请检查当前网络" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];

    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"未知错误" 
                                                        message:@"未知错误" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
    }
    return false;
}

-(BOOL) checkConnect{
    Reachability *reach=[Reachability sharedReachability];
    if([reach internetConnectionStatus]== NotReachable)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络连接失败" 
                                                        message:@"请检查网络，是否已连接WIFI或者移动数据网络" 
                                                       delegate:self cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
        staticInfo.canConnect=NO;
        return false;
    }else{
        staticInfo.canConnect=YES;
        return true;
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
}
@end
